package com.ivncorp.evnproject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Vector;

import ru.truba.touchgallery.GalleryWidget.GalleryViewPager;
import ru.truba.touchgallery.GalleryWidget.UrlPagerAdapter;
import android.app.Activity;
import android.os.Bundle;
import android.view.MenuItem;

import com.ivncorp.evnproject.model.UploadTable;

public class ActivityGalleryUrl extends Activity {

	private UploadTable table;
	private GalleryViewPager mViewPager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gallery_url);
		getActionBar().setDisplayHomeAsUpEnabled(true);

		this.table = (UploadTable) getIntent().getSerializableExtra("object");
		if (table != null) {
			Vector<String> vector = new Vector<String>();
			String img1 = table.getImage1();
			if (!img1.isEmpty() && !img1.equals("http://117.6.134.238:35")) {
				vector.add(img1);
			}
			String img2 = table.getImage2();
			if (!img2.isEmpty() && !img2.equals("http://117.6.134.238:35")) {
				vector.add(img2);
			}
			String img3 = table.getImage3();
			if (!img3.isEmpty() && !img3.equals("http://117.6.134.238:35")) {
				vector.add(img3);
			}
			String img4 = table.getImage4();
			if (!img4.isEmpty() && !img4.equals("http://117.6.134.238:35")) {
				vector.add(img4);
			}
			String img5 = table.getImage5();
			if (!img5.isEmpty() && !img5.equals("http://117.6.134.238:35")) {
				vector.add(img5);
			}

			// convert vector string to string array
			String[] url = vector.toArray(new String[vector.size()]);

			List<String> items = new ArrayList<String>();
			Collections.addAll(items, url);

			UrlPagerAdapter pagerAdapter = new UrlPagerAdapter(this, items);

			mViewPager = (GalleryViewPager) findViewById(R.id.galleryViewer);
			mViewPager.setOffscreenPageLimit(3);
			mViewPager.setAdapter(pagerAdapter);
		}

	}

	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			break;

		default:
			break;
		}
		return super.onMenuItemSelected(featureId, item);
	}

}
